package com.cctc.juc.demo.Bitc.Tmp.ADemo;

import java.util.concurrent.TimeUnit;

public class ADefaultRunDemo {

    // 效果 1： A、B 乱序执行。

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> print("A"));
        Thread t2 = new Thread(() -> print("B"));

        // 默认情况下，线程是由 CPU 调度执行的，执行顺序无法确定，即乱序执行。
        t1.start();
        t2.start();
    }

    private static void print(String threadName) {
        for (int i = 1; i <= 3; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(threadName + " -> print: " + i);
        }
    }

}
